from django.db import models

# Create your models here.
class GoodsType(models.Model):
    """
    分类
    """
    name = models.CharField(max_length=100, unique=True)

    def get_GoodsType(self):
        return self.typeName.all()

    def __str__(self):
        return self.name


class Goods(models.Model):
    """
    商品
    """
    name = models.CharField(max_length=100, unique=True)
    type = models.ForeignKey(GoodsType, related_name='typeName', on_delete=models.PROTECT)  # 防止默认的级联删除
    image = models.CharField(max_length=100)  # 路径
    price = models.FloatField()
    quantity = models.IntegerField()  # 份数
    status = models.IntegerField()

    def __str__(self):
        return self.name
